package www.cskaoyan.com.service.impl;

import www.cskaoyan.com.bean.Dormitory;
import www.cskaoyan.com.dao.DormitoryManagerDao;
import www.cskaoyan.com.service.DormitoryManagerService;

import java.sql.SQLException;
import java.util.List;

public class DormitoryManagerServiceImpl implements DormitoryManagerService {

    // 调用持久层
    DormitoryManagerDao dormitoryManagerDao;
    public DormitoryManagerServiceImpl(){
        this.dormitoryManagerDao = new DormitoryManagerDao();
    }

    @Override
    public List<Dormitory> getDormitoryList() throws SQLException {
        List<Dormitory> list = dormitoryManagerDao.getDormitoryList();

        return list;
    }

    // 创建宿舍
    @Override
    public void createDormitory(Dormitory dormitory) throws SQLException {
        dormitoryManagerDao.createDormitory(
                dormitory.getAddress(), dormitory.getDormitoryName());

    }

    // 删除宿舍
    @Override
    public void deleteDormitory(Dormitory dormitory) throws SQLException {
        int dormitoryId = dormitory.getId();

        dormitoryManagerDao.deleteDormitory(dormitoryId);

        return;
    }

    // 修改宿舍信息
    @Override
    public void changeDormitory(Dormitory dormitory) throws SQLException {
        dormitoryManagerDao.changeDormitory(
                dormitory.getId(),
                dormitory.getAddress(),
                dormitory.getDormitoryName());

    }
}
